<?php
// +----------------------------------------------------------------------
// | QbtCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.qbt8.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 千佰特 <http://www.qbt8.com>
// +----------------------------------------------------------------------
namespace plugins\qbt_alisms\controller;

use cmf\controller\PluginAdminBaseController;
use think\Db;
class AdminIndexController extends PluginAdminBaseController

{
    /**
     * 手机短信
     * @adminMenu(
     *     'name'   => '手机短信',
     *     'parent' => 'admin/Plugin/default',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '千佰特手机短信',
     *     'param'  => '',
     * )
     * @adminLog(
     *     'public/plugin/qbt_alisms/admin_index/edit|配置阿里大鱼',
     * )
     */
    public function index()
    {
        $result =  Db::name('alisms')->where('id=1')->find();
        $this->assign("info", json_decode($result['config_json'],true));
        return $this->fetch('/admin_index');
    }

    //修改
    public function edit(){
        if($_POST){
            $data1['key'] = $this->request->param('key');
            $data1['secret'] = $this->request->param('secret');
            $data1['signName'] = $this->request->param('signName');
            $data1['tempCode'] = $this->request->param('tempCode');
            $data['config_json'] = json_encode($data1);
            $result =  Db::name('alisms')->where("id = 1")->update($data);
            if ($result){
                $this->success('保存成功');
            }else{
                $this->error('保存失败');
            }
        }else{
            $info =  Db::name('alisms')->where("id = 1")->find();
            $this->assign("info", json_decode($info['config_json'],true));
            return $this->fetch('/edit');
        }
    }
}